package com.example.rbacmanage.config;

import com.example.rbacmanage.property.DatabaseProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {
    @Autowired
    private DatabaseProperty databaseProperty;
    @Bean
    public DataSource getDataSource(){
        DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName(databaseProperty.getDriverClassName());
        dataSourceBuilder.url(databaseProperty.getUrl());
        dataSourceBuilder.username(databaseProperty.getUsername());
        dataSourceBuilder.password(databaseProperty.getPassword());
        return dataSourceBuilder.build();
    }
}
